import datetime

from sqlalchemy import Column, Integer, DateTime, String, text
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.ext.asyncio import async_sessionmaker
from sqlalchemy.ext.asyncio import AsyncAttrs
from sqlalchemy.orm import DeclarativeBase
from urllib.parse import quote_plus

from sqlmodel import SQLModel

from config.env import MysqlConfig

ASYNC_SQLALCHEMY_DATABASE_URL = (
    f'mysql+asyncmy://{MysqlConfig.db_username}:{quote_plus(MysqlConfig.db_password)}@'
    f'{MysqlConfig.db_host}:{MysqlConfig.db_port}/{MysqlConfig.db_database}'
)


async_engine = create_async_engine(
    ASYNC_SQLALCHEMY_DATABASE_URL,
    echo=MysqlConfig.db_echo,
    max_overflow=MysqlConfig.db_max_overflow,
    pool_size=MysqlConfig.db_pool_size,
    pool_recycle=MysqlConfig.db_pool_recycle,
    pool_timeout=MysqlConfig.db_pool_timeout,
)
AsyncSessionLocal = async_sessionmaker(autocommit=False, autoflush=False, bind=async_engine)

#
# class Base(SQLModel, abstract=True):
#     pass